package com.xuan.task.Mapper;

import com.xuan.task.domain.EBookAndCount;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface ElectronicBookMapper {

    /**
     * 根据类型获取电子书列表
     *
     * @param type  电子书类型
     * @return
     */
    @Select( "select book_num  from electronic_book  where type=#{type}" )
    List<String> getElectronicBookByType(Integer type);

    //电子书中单词的数量
    @Select( "select count(*) from (" +
            "   SELECT DISTINCT word FROM resource_word_relation r" +
            "   join vocabulary_resource_library vr on r.vocabulary_resource_num = vr.resource_library_num" +
            "   WHERE vocabulary_resource_num in (select resource_library_num  from  electronic_library_relation where book_num =#{bookNum})" +
            "   and word in (select word from vocabulary where audio_path!='' and is_delete=0 )) tt" )
    int getWordCountByBookNum(String bookNum);


    //获取每个电子书中单词的数量
    @Select( "<script> select book_num,count(*) num from (" +
            " SELECT DISTINCT word,e.book_num FROM resource_word_relation r" +
            " join vocabulary_resource_library vr on r.vocabulary_resource_num = vr.resource_library_num" +
            " join electronic_library_relation e on r.vocabulary_resource_num = e.resource_library_num" +
            " where e.book_num in  " +
            " <foreach collection='bookNumList' open='(' item='num' separator=',' close=')'>#{num}</foreach> " +
            " and word in (select word from vocabulary where audio_path!='' and is_delete=0 ) ) tt" +
            " group by book_num </script>" )
    List<EBookAndCount> getEBookWordCountByBookNum(@Param( "bookNumList" ) List<String> bookNumList);








}
